package com.wiscofile.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.wiscofile.pojo.WiscoPlanprojectApply;

/**
 * A data access object (DAO) providing persistence and search support for
 * WiscoPlanprojectApply entities. Transaction control of the save(), update()
 * and delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.wiscofile.pojo.WiscoPlanprojectApply
 * @author MyEclipse Persistence Tools
 */

public class WiscoPlanprojectApplyDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory
			.getLog(WiscoPlanprojectApplyDAO.class);
	// property constants
	public static final String PROJECTNAME = "projectname";
	public static final String CAPITALSOURCE = "capitalsource";
	public static final String INVESTMENTPLAN = "investmentplan";
	public static final String PROJECTCODE = "projectcode";
	public static final String ADVICEADRESS = "adviceadress";
	public static final String APPLYADRESS = "applyadress";
	public static final String APPLYCOMPARY = "applycompary";
	public static final String APPLYUSER = "applyuser";
	public static final String TEL = "tel";

	public void save(WiscoPlanprojectApply transientInstance) {
		log.debug("saving WiscoPlanprojectApply instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(WiscoPlanprojectApply persistentInstance) {
		log.debug("deleting WiscoPlanprojectApply instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public WiscoPlanprojectApply findById(java.lang.String id) {
		log.debug("getting WiscoPlanprojectApply instance with id: " + id);
		try {
			WiscoPlanprojectApply instance = (WiscoPlanprojectApply) getSession()
					.get("com.wiscofile.pojo.WiscoPlanprojectApply", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(WiscoPlanprojectApply instance) {
		log.debug("finding WiscoPlanprojectApply instance by example");
		try {
			List results = getSession().createCriteria(
					"com.wiscofile.pojo.WiscoPlanprojectApply").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding WiscoPlanprojectApply instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from WiscoPlanprojectApply as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByProjectname(Object projectname) {
		return findByProperty(PROJECTNAME, projectname);
	}

	public List findByCapitalsource(Object capitalsource) {
		return findByProperty(CAPITALSOURCE, capitalsource);
	}

	public List findByInvestmentplan(Object investmentplan) {
		return findByProperty(INVESTMENTPLAN, investmentplan);
	}

	public List findByProjectcode(Object projectcode) {
		return findByProperty(PROJECTCODE, projectcode);
	}

	public List findByAdviceadress(Object adviceadress) {
		return findByProperty(ADVICEADRESS, adviceadress);
	}

	public List findByApplyadress(Object applyadress) {
		return findByProperty(APPLYADRESS, applyadress);
	}

	public List findByApplycompary(Object applycompary) {
		return findByProperty(APPLYCOMPARY, applycompary);
	}

	public List findByApplyuser(Object applyuser) {
		return findByProperty(APPLYUSER, applyuser);
	}

	public List findByTel(Object tel) {
		return findByProperty(TEL, tel);
	}

	public List findAll() {
		log.debug("finding all WiscoPlanprojectApply instances");
		try {
			String queryString = "from WiscoPlanprojectApply";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public WiscoPlanprojectApply merge(WiscoPlanprojectApply detachedInstance) {
		log.debug("merging WiscoPlanprojectApply instance");
		try {
			WiscoPlanprojectApply result = (WiscoPlanprojectApply) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(WiscoPlanprojectApply instance) {
		log.debug("attaching dirty WiscoPlanprojectApply instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(WiscoPlanprojectApply instance) {
		log.debug("attaching clean WiscoPlanprojectApply instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}